﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional

namespace TrackSystem.EntityFramework.Migrations
{
    /// <inheritdoc />
    public partial class cm12 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DeleteData(
                table: "AspNetRoles",
                keyColumn: "Id",
                keyValue: "213a61b2-b297-4e59-98f8-07f2974005c2");

            migrationBuilder.DeleteData(
                table: "AspNetRoles",
                keyColumn: "Id",
                keyValue: "4e943962-c294-4db4-9421-d9fa3c2f2061");

            migrationBuilder.DeleteData(
                table: "AspNetRoles",
                keyColumn: "Id",
                keyValue: "946bf491-59d6-4788-96b1-0a98c358f226");

            migrationBuilder.DeleteData(
                table: "AspNetRoles",
                keyColumn: "Id",
                keyValue: "aa5893de-e696-4b53-8019-39950930301f");

            migrationBuilder.DeleteData(
                table: "AspNetRoles",
                keyColumn: "Id",
                keyValue: "c1d6cf2e-6885-4f8c-8c02-d4d1c46a0d84");

            migrationBuilder.AlterColumn<string>(
                name: "Value",
                table: "Alarm",
                type: "longtext",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "longtext")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Slave",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Description = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Protocol = table.Column<int>(type: "int", nullable: false),
                    PortCategory = table.Column<int>(type: "int", nullable: false),
                    RemoteIP = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    RemotePort = table.Column<int>(type: "int", nullable: false),
                    LocalIP = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LocalPort = table.Column<int>(type: "int", nullable: false),
                    Comx = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    BaudRate = table.Column<int>(type: "int", nullable: false),
                    SerialParams = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Station = table.Column<int>(type: "int", nullable: false),
                    RoList = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    RwList = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ProtocolDefine = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Cycle = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Slave", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.InsertData(
                table: "AspNetRoles",
                columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
                values: new object[,]
                {
                    { "45fcedc8-30d6-47b3-88ed-996e857956a3", null, "Guest", "Guest" },
                    { "5366e293-1e59-4074-af40-ca8cb0165e49", null, "Admin", "ADMIN" },
                    { "962d30ab-2922-464f-95b4-097b86c6aea7", null, "Eng", "Engineer" },
                    { "9b2ee2f1-eeb5-4e39-9cd5-475d9f86703c", null, "User", "User" },
                    { "be884eba-d82f-4ca0-9562-10ea5156a0e7", null, "Op", "Operator" }
                });

            migrationBuilder.UpdateData(
                table: "Channel",
                keyColumn: "Id",
                keyValue: 1,
                column: "Ip",
                value: "127.0.0.1");

            migrationBuilder.UpdateData(
                table: "Logic",
                keyColumn: "Id",
                keyValue: 1,
                columns: new[] { "ClacateFormula", "ResultReg" },
                values: new object[] { "MotorTemp_RW1 = Port3_Enable ? int(rand(Port2_Lapse )) : 0;", "MotorTemp_RW1" });

            migrationBuilder.UpdateData(
                table: "Logic",
                keyColumn: "Id",
                keyValue: 2,
                columns: new[] { "ClacateFormula", "ConditionFormula", "ResultReg" },
                values: new object[] { "MotorTemp_RW2 = Port1_Connected ?int(rand(400)) : 0;", "Port2_Enable", "MotorTemp_RW2" });

            migrationBuilder.UpdateData(
                table: "Loop",
                keyColumn: "Id",
                keyValue: 1,
                columns: new[] { "OPName", "PVName", "SVName" },
                values: new object[] { "MotorTemp_RW4", "MotorTemp_RW1", "DestDepth" });

            migrationBuilder.UpdateData(
                table: "Sensor",
                keyColumn: "Id",
                keyValue: 1,
                column: "Description",
                value: "电源监测");

            migrationBuilder.UpdateData(
                table: "Sensor",
                keyColumn: "Id",
                keyValue: 2,
                columns: new[] { "Description", "RO_Length" },
                values: new object[] { "漏水监测", 3 });

            migrationBuilder.UpdateData(
                table: "Sensor",
                keyColumn: "Id",
                keyValue: 3,
                columns: new[] { "Description", "RO_Length" },
                values: new object[] { "电机控制", 2 });

            migrationBuilder.UpdateData(
                table: "Sensor",
                keyColumn: "Id",
                keyValue: 4,
                columns: new[] { "Description", "RW_Length" },
                values: new object[] { "CTD传感器", 5 });

            migrationBuilder.InsertData(
                table: "Slave",
                columns: new[] { "Id", "BaudRate", "Comx", "Cycle", "Description", "LocalIP", "LocalPort", "Name", "PortCategory", "Protocol", "ProtocolDefine", "RemoteIP", "RemotePort", "RoList", "RwList", "SerialParams", "Station" },
                values: new object[] { 1, 9600, "", 100, "HMI接口数据服务器", "127.0.0.1", 6001, "HMIData", 0, 1, "", "127.0.0.1", 7010, "MotorTemp_RO0,MotorTemp_RO1,MotorTemp_RO2", "MotorTemp_RW0,MotorTemp_RW1,MotorTemp_RW2,MotorTemp_RW3", "N-8-1", 1 });

            migrationBuilder.UpdateData(
                table: "var",
                keyColumn: "Id",
                keyValue: 1,
                column: "Name",
                value: "Port1_Enable");

            migrationBuilder.UpdateData(
                table: "var",
                keyColumn: "Id",
                keyValue: 2,
                column: "Name",
                value: "Port2_Enable");

            migrationBuilder.UpdateData(
                table: "var",
                keyColumn: "Id",
                keyValue: 12,
                columns: new[] { "DataType", "Description", "Name", "ReadOnly", "Serial", "snrloopId", "snrloopIndex" },
                values: new object[] { 2, "定深目标值", "DestDepth", false, 10, 0, 0 });

            migrationBuilder.CreateIndex(
                name: "IX_Slave_Id",
                table: "Slave",
                column: "Id",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Slave_Name",
                table: "Slave",
                column: "Name",
                unique: true);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Slave");

            migrationBuilder.DeleteData(
                table: "AspNetRoles",
                keyColumn: "Id",
                keyValue: "45fcedc8-30d6-47b3-88ed-996e857956a3");

            migrationBuilder.DeleteData(
                table: "AspNetRoles",
                keyColumn: "Id",
                keyValue: "5366e293-1e59-4074-af40-ca8cb0165e49");

            migrationBuilder.DeleteData(
                table: "AspNetRoles",
                keyColumn: "Id",
                keyValue: "962d30ab-2922-464f-95b4-097b86c6aea7");

            migrationBuilder.DeleteData(
                table: "AspNetRoles",
                keyColumn: "Id",
                keyValue: "9b2ee2f1-eeb5-4e39-9cd5-475d9f86703c");

            migrationBuilder.DeleteData(
                table: "AspNetRoles",
                keyColumn: "Id",
                keyValue: "be884eba-d82f-4ca0-9562-10ea5156a0e7");

            migrationBuilder.UpdateData(
                table: "Alarm",
                keyColumn: "Value",
                keyValue: null,
                column: "Value",
                value: "");

            migrationBuilder.AlterColumn<string>(
                name: "Value",
                table: "Alarm",
                type: "longtext",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "longtext",
                oldNullable: true)
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.InsertData(
                table: "AspNetRoles",
                columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
                values: new object[,]
                {
                    { "213a61b2-b297-4e59-98f8-07f2974005c2", null, "Op", "Operator" },
                    { "4e943962-c294-4db4-9421-d9fa3c2f2061", null, "Guest", "Guest" },
                    { "946bf491-59d6-4788-96b1-0a98c358f226", null, "Eng", "Engineer" },
                    { "aa5893de-e696-4b53-8019-39950930301f", null, "Admin", "ADMIN" },
                    { "c1d6cf2e-6885-4f8c-8c02-d4d1c46a0d84", null, "User", "User" }
                });

            migrationBuilder.UpdateData(
                table: "Channel",
                keyColumn: "Id",
                keyValue: 1,
                column: "Ip",
                value: "10.3.41.241");

            migrationBuilder.UpdateData(
                table: "Logic",
                keyColumn: "Id",
                keyValue: 1,
                columns: new[] { "ClacateFormula", "ResultReg" },
                values: new object[] { "Port1_Enabled ? 1 : 0", "Port1_Enabled" });

            migrationBuilder.UpdateData(
                table: "Logic",
                keyColumn: "Id",
                keyValue: 2,
                columns: new[] { "ClacateFormula", "ConditionFormula", "ResultReg" },
                values: new object[] { "Port2_Enabled ? 1 : 0", "Port2_Connected", "Port2_Enabled" });

            migrationBuilder.UpdateData(
                table: "Loop",
                keyColumn: "Id",
                keyValue: 1,
                columns: new[] { "OPName", "PVName", "SVName" },
                values: new object[] { "CTD1_RO2", "CTD1_RO1", "CTD1_RW1" });

            migrationBuilder.UpdateData(
                table: "Sensor",
                keyColumn: "Id",
                keyValue: 1,
                column: "Description",
                value: "Power Control");

            migrationBuilder.UpdateData(
                table: "Sensor",
                keyColumn: "Id",
                keyValue: 2,
                columns: new[] { "Description", "RO_Length" },
                values: new object[] { "Leak Detect", 0 });

            migrationBuilder.UpdateData(
                table: "Sensor",
                keyColumn: "Id",
                keyValue: 3,
                columns: new[] { "Description", "RO_Length" },
                values: new object[] { "Motor Detect", 0 });

            migrationBuilder.UpdateData(
                table: "Sensor",
                keyColumn: "Id",
                keyValue: 4,
                columns: new[] { "Description", "RW_Length" },
                values: new object[] { "CTD Sensor", 0 });

            migrationBuilder.UpdateData(
                table: "var",
                keyColumn: "Id",
                keyValue: 1,
                column: "Name",
                value: "Port1_Enabled");

            migrationBuilder.UpdateData(
                table: "var",
                keyColumn: "Id",
                keyValue: 2,
                column: "Name",
                value: "Port1_Connected");

            migrationBuilder.UpdateData(
                table: "var",
                keyColumn: "Id",
                keyValue: 12,
                columns: new[] { "DataType", "Description", "Name", "ReadOnly", "Serial", "snrloopId", "snrloopIndex" },
                values: new object[] { 1, "Var from channel", "Port3_Lapse", true, 0, 3, 3 });
        }
    }
}
